package com.greatchn.resource_server.web.controller;

import cn.hutool.json.JSONUtil;
import com.greatchn.resource_server.util.Result;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;

/**
 * @SaleController: 销售
 * @author: ZBoHang
 * @time: 2023/2/28 17:46
 */
@RequestMapping("/sale")
@RestController
public class SaleController {

    /**
     * get info
     */
    @PostMapping("/getInfo")
    public Result getInfo(Principal principal, Authentication authentication) {

        Authentication localAuth = SecurityContextHolder.getContext().getAuthentication();
        OAuth2AuthenticationDetails details = ((OAuth2AuthenticationDetails) localAuth.getDetails());

        System.out.println(JSONUtil.toJsonPrettyStr(details.getDecodedDetails()));

        return Result.success(authentication);
    }

    /**
     * get info
     */
    @PostMapping("/check")
    public Result check(String name) {

        return Result.success(name);
    }
}
